<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>业务员管理-OMS订单管理系统</title>

</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li class="layui-this">业务员管理</li>
        </ul>
    </div>
    <style>
        .hideAddress{
            width: 300px;
            display: inline-block;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    <!-- content starts -->
    <!--    <blockquote class="layui-elem-quote">订单总览</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" th:action="@{/sales_man/list}">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="trueName"  th:value="${trueName}" placeholder="姓名" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="mobile" id="mobile" th:value="${mobile}" placeholder="手机号" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>

                    <div class="layui-inline">
                        <a class="layui-btn layui-btn layui-btn-primary"  href="/sales_man/add">添加业务员</a>
                    </div>

                </div>

            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/css/order_list.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                <th>ID</th>
                <th>真实姓名</th>
                <th >手机号</th>
                <th></th>
                <th>添加时间</th>
                <th>操作</th>
            </tr>
            <tr th:each="item:${list}">
                <td th:text="${item.id}"></td>
                <td th:text="${item.trueName}"></td>
                <td th:text="${item.mobile}"></td>
                <td th:text="${item.summary}"></td>
                <td>
                    <p th:text="${ #dates.format(item.addTime * 1000, 'yyyy-MM-dd HH:mm:ss')}"></p>
                </td>
                <td>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">

    </div>

    <!--<script src="/jquery-3.3.1.min.js"></script>-->
    <!--    <script type="text/javascript" src="/goods/Tips/Tips.min.js"></script>-->
    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;

        //计算天数差的函数，通用
        function DateDiff(sDate1, sDate2) { //sDate1和sDate2是2019-3-12格式
            var aDate, oDate1, oDate2, iDays
            aDate = sDate1.split("-")
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为9-25-2017格式
            aDate = sDate2.split("-")
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
            return iDays
        }

        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            //下拉框默认值
            var status = '[[${status}]]';
            if (status != '')
                $("#status").val(status);

            // var saleType = '[[${saleType}]]';
            // if(saleType!='')
            //     $("#type").val(saleType);

            form.render();
            $(function () {


                //打印快递面单
                $(".print_express").click(function () {
                    var id = $(this).attr("order-id");
                    // console.log(id);
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '打印订单快递单',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['940px', '90%'],
                        content: '/order/order_send_express?id=' + id //iframe的url
                    });
                })

                $(".order_send_confirm").click(function () {
                    var orderId = $(this).attr("order-id");
                    layer.open({
                        type: 2,
                        title: '订单发货',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['940px', '90%'],
                        content: '/order/order_send?id=' + orderId //iframe的url
                    });
                })

                $(".order_cancel").click(function () {
                    if (confirm("确定要取消订单吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order/order_cancel",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("已取消！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }

                })

                $(".order_send").click(function () {
                    if (confirm("确定要发货吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order/order_send",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("发货成功！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }
                })

                //导出当前结果
                $("#excel_btn").click(function () {
                    //组合条件
                    var url = "/order/order_list_excel_export?excel=1";
                    var orderNum = $("input[name=orderNum]").val();
                    var mobile = $("input[name=contactMobile]").val();
                    var status = $("#status").val();
                    var startTime = $("input[name=startTime]").val();
                    var endTime = $("input[name=endTime]").val();

                    if (orderNum != '') {
                        url += "&orderNum=" + orderNum;
                    }
                    if (mobile != '') {
                        url += "&contactMobile=" + mobile;
                    }
                    if (status != '') {
                        url += "&status=" + status;
                    }
                    if (startTime != '') {
                        url += "&startTime=" + startTime;
                    }
                    if (endTime != '') {
                        url += "&endTime=" + endTime;
                    }

                    if (confirm("当前有[[${totalSize}]]条数据，确认要导出吗？")) {
                        window.open(url, "_blank");
                        //?billNo=&contractNo=&startTime=2019-12-13&endTime=2019-12-13
                    }
                })


                //取消订单
                $(".cancel_order").click(function () {
                    if (confirm("确定要取消订单吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order_confirm/order_cancel",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("取消成功！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }
                })
            })//$(function(){})
        });

    </script>


</div>
</body>
</html>
